import { createI18n } from 'vue-i18n'
import { useAppStoreHook } from '@/stores/modules/app'
import type { WritableComputedRef } from 'vue'
import en from '@/locales/i18n/en'
import cn from '@/locales/i18n/cn'

const messages = { en, cn }
const useAppStore = useAppStoreHook()
const I18n = createI18n({
  legacy: false,
  globalInjection: true,
  fallbackLocale: useAppStore.fallbackLocale,
  locale: useAppStore.locale,
  messages
})
export default I18n

// 切换的类型
export type LocaleType = 'cn' | 'en'

// 切换语言
export const SwitchLanguages = (Locale: LocaleType, locale: WritableComputedRef<string>) => {
  useAppStore.SET_LOCALE(Locale)
  locale.value = Locale
}
